package com.train.order.mq.producer;

import com.train.common.constants.mq.MqEventSourceConstants;
import com.train.common.constants.mq.MqTopicConstants;
import com.train.mq.support.RocketMQSupport;
import com.train.order.event.confirmorder.ConfirmOrderEventBody;
import com.train.order.event.confirmorder.ConfirmOrderEventHeader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class ConfirmOrderProducer {

    @Autowired
    private RocketMQSupport rocketMQSupport;

    /**
     * 发送订单确认消息
     * @param id
     * @param date
     * @param trainCode
     */
    public void sendConfirmOrder(Long id, LocalDate date, String trainCode) {
        ConfirmOrderEventHeader eventHeader = new ConfirmOrderEventHeader(id, MqEventSourceConstants.ORDER_CONFIRM_SOURCE);
        ConfirmOrderEventBody eventBody = new ConfirmOrderEventBody();
        eventBody.setDate(date);
        eventBody.setTrainCode(trainCode);
        rocketMQSupport.sendSyncMessage(MqTopicConstants.ORDER_CONFIRM_TOPIC, eventBody, eventHeader);
    }
}
